package cn.oms.oms.controller;


import cn.oms.oms.entity.Item;
import cn.oms.oms.entity.Order;
import cn.oms.oms.service.IItemService;
import cn.oms.oms.service.IOrderService;
import cn.oms.oms.vo.ItemVo;
import cn.oms.oms.vo.OrderVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/order")
@Slf4j
public class OrderController {

    @Autowired
    public IOrderService orderService;

    /**
     * 根据查询条件查询医嘱列表
     * @param orderVo
     * @return
     */
    @PostMapping("/selectOrderList")
    public PageInfo<Order> selectOrderList(OrderVo orderVo){
        if(orderVo.getPageNum()==null||orderVo.getPageNum()==0){
            orderVo.setPageNum(1);
        }
        if(orderVo.getPageSize()==null||orderVo.getPageSize()==0){
            orderVo.setPageSize(10);
        }

        log.debug("接收到信息:{}",orderVo);
        PageInfo<Order> pageInfo = orderService.selectOrderList(orderVo);
        return pageInfo;
    }


    /**
     * 根据医嘱ID查询医嘱详情
     * @param orderVo
     * @return
     */
    @PostMapping("/selectOrderDetail")
    public Order selectOrderDetail(OrderVo orderVo){
        log.debug("接收到信息:{}",orderVo);
        Order order = orderService.selectOrderDetail(orderVo);
        return order;
    }

    /**
     * 新增医嘱
     * @param orderVo
     * @return
     */
    @PostMapping("/addOrder")
    public String addOrder(OrderVo orderVo){
        log.debug("接收到信息:{}",orderVo);
        String res = orderService.addOrder(orderVo);
        return res;
    }

    /**
     * 修改医嘱
     * @param orderVo
     * @return
     */
    @PostMapping("/updateOrder")
    public String updateOrder(OrderVo orderVo){
        log.debug("接收到信息:{}",orderVo);
        String res = orderService.updateOrder(orderVo);
        return res;
    }

    /**
     * 删除医嘱
     * @param id
     * @return
     */
    @GetMapping("/deleteOrder/{id}")
    public String deleteOrder(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = orderService.deleteOrder(id);
        return res;
    }


    /**
     * 医嘱签名
     * @param orderVo
     * @return
     */
    @PostMapping("/orderSignature")
    public String orderSignature(OrderVo orderVo){
        log.debug("接收到信息:{}",orderVo);
        String res = orderService.orderSignature(orderVo);
        return res;
    }

    /**
     * 医嘱批量签名
     * @param orderVo
     * @return
     */
    @PostMapping("/orderSignatureList")
    public String orderSignatureList(OrderVo orderVo){
        log.debug("接收到信息:{}",orderVo);
        String res = orderService.orderSignatureList(orderVo);
        return res;
    }

}
